package b2.widget.store
{
	import b2.config.*;
	import b2.net.*;
	import b2.player.*;
	import b2.util.*;
	import b2.widget.*;
	
	import flash.display.Sprite;
	import flash.filters.*;
	import flash.text.*;

	public class StoreItemMessage extends Sprite
	{
		public function StoreItemMessage(objectIndex:int)
		{
			super();
			var objectConfig:CommonObjConfig = Config.objectConfigs[objectIndex];
			var basicLevel:int = 0;
			var strengthenLevel:int = 0;
			var roundRecContainer:Sprite = new Sprite();
			//名字
			var nameText:TextField = new TextField();
			nameText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			nameText.selectable = false;
        	nameText.autoSize = TextFieldAutoSize.LEFT;
			nameText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0xFFFFFF, true);
			
			//具体信息
			var tipText:TextField = new TextField();
			tipText.selectable = false;
        	tipText.autoSize = TextFieldAutoSize.LEFT;
        	tipText.width = 180;
        	tipText.wordWrap = true;
			tipText.multiline = true;
			tipText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0x000000, true);
			
			var me:PlayerInfo = PlayerInfoManager.getInstance().players[PlayerInfoManager.getInstance().myUserId];
			if (!objectConfig.onSaleFlag)
			{
				tipText.htmlText = "<i>非卖品</i>"; 
			}
			else
			{
				if (objectConfig.priceGas > 0)
				{
					var price:int = objectConfig.discount > 0 ? objectConfig.priceGas * objectConfig.discount / 100 : objectConfig.priceGas;
					tipText.htmlText = "<i>Q点: " + price + "</i>";
					if (objectConfig.type != 2)
					{
						basicLevel = 3;
					}
				}
				else if (objectConfig.priceHonour > 0)
				{
					tipText.htmlText = "<i>荣誉勋章: " + objectConfig.priceHonour + "</i>";
				}
				else
				{
					tipText.htmlText = "<i>石油: " + objectConfig.priceOil + "</i>";
				}
			}
			var quality:int = basicLevel * 5 + strengthenLevel;
			//装备
			if (objectConfig.type == 1)
			{
				var equipConfig:EquipConfig = objectConfig as EquipConfig;
				//战力
				var fpSprite:Sprite = getFightPoint(equipConfig.fightPoint[quality]);
				fpSprite.x = 180 - fpSprite.width;
				fpSprite.y = 1;
				roundRecContainer.addChild(fpSprite);
				nameText.text = Config.basicConfig.equipSuitName[equipConfig.suitIndex] + "的" + objectConfig.name.toString();
				tipText.htmlText += "部位: " + Config.basicConfig.equipPosName[equipConfig.position];
				tipText.htmlText += "品质: <font color='#"+ Config.basicConfig.objectBasicLevelColor[basicLevel].substr(2) + "'>" + 
					Config.basicConfig.objectBasicLevel[basicLevel] + Config.basicConfig.objectStrengthenLevel[strengthenLevel] + "</font>";
				tipText.htmlText += equipConfig.getDescription(quality);
				//横线
				roundRecContainer.graphics.lineStyle(1, 0, 0.5);
				roundRecContainer.graphics.moveTo(0, tipText.height + 30);
				roundRecContainer.graphics.lineTo(190, tipText.height + 30);
				var highestLevelContainer:Sprite = new Sprite();
				//满级
				var highestLevelText:TextField = new TextField();
				highestLevelText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
				highestLevelText.selectable = false;
	        	highestLevelText.autoSize = TextFieldAutoSize.LEFT;
				highestLevelText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0xFFFFFF, true);
				highestLevelText.text = "满级属性";
				highestLevelText.y = tipText.height + 40;
				highestLevelContainer.addChild(highestLevelText);
				fpSprite = getFightPoint(equipConfig.fightPoint[24]);
				fpSprite.x = 180 - fpSprite.width;
				fpSprite.y = highestLevelText.y;
				highestLevelContainer.addChild(fpSprite);
				//满级效果
				var highestTipText:TextField = new TextField();
				highestTipText.selectable = false;
	        	highestTipText.autoSize = TextFieldAutoSize.LEFT;
	        	highestTipText.width = 180;
	        	highestTipText.wordWrap = true;
				highestTipText.multiline = true;
				highestTipText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0x000000, true);
				highestTipText.htmlText = "品质: <font color='#"+ Config.basicConfig.objectBasicLevelColor[4].substr(2) + "'>" + 
					Config.basicConfig.objectBasicLevel[4] + Config.basicConfig.objectStrengthenLevel[4] + "</font>";
				highestTipText.htmlText += equipConfig.getDescription(24);
				highestTipText.y = highestLevelText.y + 20;
				highestLevelContainer.addChild(highestTipText);
				highestLevelContainer.x = 10;
				roundRecContainer.addChild(highestLevelContainer); 
			}
			//坦克
			else if (objectConfig.type == 0)
			{
				var tankConfig:TankConfig = objectConfig as TankConfig;
				//战力
				fpSprite = getFightPoint(tankConfig.fightPoint[quality]);
				fpSprite.x = 180 - fpSprite.width;
				fpSprite.y = 1;
				roundRecContainer.addChild(fpSprite);
				nameText.text = objectConfig.name.toString();
				tipText.htmlText += "品质: <font color='#"+ Config.basicConfig.tankBasicLevelColor[basicLevel].substr(2) + "'>" + 
					Config.basicConfig.tankBasicLevel[basicLevel] + Config.basicConfig.tankStrengthenLevel[strengthenLevel] + "</font>";
				tipText.htmlText += tankConfig.getDescription(quality);
				//横线
				roundRecContainer.graphics.lineStyle(1, 0, 0.5);
				roundRecContainer.graphics.moveTo(0, tipText.height + 30);
				roundRecContainer.graphics.lineTo(190, tipText.height + 30);
				highestLevelContainer = new Sprite();
				//满级
				highestLevelText = new TextField();
				highestLevelText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
				highestLevelText.selectable = false;
	        	highestLevelText.autoSize = TextFieldAutoSize.LEFT;
				highestLevelText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0xFFFFFF, true);
				highestLevelText.text = "满级属性";
				highestLevelText.y = tipText.height + 40;
				highestLevelContainer.addChild(highestLevelText);
				fpSprite = getFightPoint(tankConfig.fightPoint[24]);
				fpSprite.x = 180 - fpSprite.width;
				fpSprite.y = highestLevelText.y;
				highestLevelContainer.addChild(fpSprite);
				//满级效果
				highestTipText = new TextField();
				highestTipText.selectable = false;
	        	highestTipText.autoSize = TextFieldAutoSize.LEFT;
	        	highestTipText.width = 180;
	        	highestTipText.wordWrap = true;
				highestTipText.multiline = true;
				highestTipText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0x000000, true);
				highestTipText.htmlText = "品质: <font color='#"+ Config.basicConfig.tankBasicLevelColor[4].substr(2) + "'>" + 
					Config.basicConfig.tankBasicLevel[4] + Config.basicConfig.tankStrengthenLevel[4] + "</font>";
				highestTipText.htmlText += "攻击: <font color='#00AA00'>" + parseInt(tankConfig.attackPoint[24]) + "</font>\t\t" + 
						"防御: <font color='#00AA00'>" + parseInt(tankConfig.armPoint[24]) + "</font>";
				highestTipText.htmlText += "生命: <font color='#00AA00'>" + parseInt(tankConfig.healthPoint[24]) + "</font>\t\t" + 
						"暴击: <font color='#00AA00'>" + parseInt(tankConfig.criticalAttackRatio[24]) + "</font>";
				highestTipText.htmlText += "能量: <font color='#00AA00'>" + parseInt(tankConfig.energyPoint[24]) + "</font>";
				highestTipText.y = highestLevelText.y + 20;
				highestLevelContainer.addChild(highestTipText);
				highestLevelContainer.x = 10;
				roundRecContainer.addChild(highestLevelContainer);
			}
			else
			{
				nameText.text = objectConfig.name.toString();
				tipText.htmlText += "作用: " + objectConfig.description;
			}
			
			tipText.y = 20;
			
			roundRecContainer.addChild(nameText);
			roundRecContainer.addChild(tipText);

			var roundRec:RoundRec = new RoundRec(210, roundRecContainer.height + 30, 0.8, BFont.roundRecColor);
			roundRecContainer.x = 10;
			roundRecContainer.y = 10;
			addChild(roundRec);
			addChild(roundRecContainer);
		}
		
		private function getFightPoint(fp:int):Sprite
		{
			var fpContainer:Sprite = new Sprite();
			//战力图标
			var CampIcon:Class = ResourceHelper.getInstance().getClassByName("CampIcon");
			var fpIcon:Sprite = new CampIcon();
			fpIcon.width = 20;
			fpIcon.height = 20;
			fpContainer.addChild(fpIcon);
			//坦克战力
			var fightPoint:TextField = new TextField();
			fightPoint.selectable = false;
        	fightPoint.autoSize = TextFieldAutoSize.LEFT;
			fightPoint.defaultTextFormat = new TextFormat("微软雅黑", 12, 0xFFFFFF);
			fightPoint.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			fightPoint.text = fp.toString();
			fightPoint.x = 25;
			fpContainer.addChild(fightPoint);
			return fpContainer;
		}
		
	}
}